function twoSum(nums, target) {
    // es6 有map 可以直接用
    // 语言都提供了一些内置的数据结构 []
    const diffs =new Map();  
    const len = nums.length;
    for(let i=0;i<len;i++){
        const diff = target -nums[i];
        if(diffs.has(diff)){
            return [diffs.get(diff),i];
        }
        else{
            diffs.set(nums[i],i);
        }
    }
}
console.log(twoSum([2,7,11,15],9));